﻿namespace WDE.Helpers
{
    using System;
    using System.Collections.Generic;

    public sealed class Xtype
    {
        public Xtype(string name, InnerEnum innerEnumValue)
        {
            this._innerEnumValue = innerEnumValue;
            this._nameValue = name;
        }

        //public static readonly Xtype EDITOR = new Xtype("EDITOR", InnerEnum.EDITOR);

        //public static readonly Xtype EDITORGRID = new Xtype("EDITORGRID", InnerEnum.EDITORGRID);

        //public static readonly Xtype FLASH = new Xtype("FLASH", InnerEnum.FLASH);

        //public static readonly Xtype GRID = new Xtype("GRID", InnerEnum.GRID);

        //public static readonly Xtype LISTVIEW = new Xtype("LISTVIEW", InnerEnum.LISTVIEW);

        //public static readonly Xtype TREEPANEL = new Xtype("TREEPANEL", InnerEnum.TREEPANEL);

        //public static readonly Xtype VIEWPORT = new Xtype("VIEWPORT", InnerEnum.VIEWPORT);

        //public static readonly Xtype BOX = new Xtype("BOX", InnerEnum.BOX);

        //public static readonly Xtype BUTTONGROUP = new Xtype("BUTTONGROUP", InnerEnum.BUTTONGROUP);

        //public static readonly Xtype COLORPALETTE = new Xtype("COLORPALETTE", InnerEnum.COLORPALETTE);

        //public static readonly Xtype COMPONENT = new Xtype("COMPONENT", InnerEnum.COMPONENT);

        //public static readonly Xtype CYCLE = new Xtype("CYCLE", InnerEnum.CYCLE);

        public static readonly Xtype FIRSTROW = new Xtype(".x-grid3-row-first", InnerEnum.FIRSTROW);

        public static readonly Xtype EASMENUSUBITEM = new Xtype(".eas-main-menu-submenu-item", InnerEnum.EASMENUSUBITEM);

        public static readonly Xtype EASMENU = new Xtype(".eas-main-menu-item-text", InnerEnum.EASMENU);

        public static readonly Xtype MENUSUBITEMCONTAINER = new Xtype(".bp-main-menu-submenu-container", InnerEnum.MENUSUBITEMCONTAINER);

        public static readonly Xtype MENUITEM = new Xtype(".x-menu-item-text", InnerEnum.MENUITEM);

        public static readonly Xtype NUMBERFIELD = new Xtype("NUMBERFIELD", InnerEnum.NUMBERFIELD);

        public static readonly Xtype DATEFIELD = new Xtype(".x-form-text", InnerEnum.DATEFIELD);

        //для Ext 4 ".x-btn:children()"
        public static readonly Xtype BUTTON = new Xtype(".x-btn", InnerEnum.BUTTON);

        public static readonly Xtype DATEPICKER = new Xtype(".x-form-date-trigger", InnerEnum.DATEPICKER);

        public static readonly Xtype TABPANEL = new Xtype(".x-tab-panel .x-tab-strip-text", InnerEnum.TABPANEL);

        public static readonly Xtype PANEL = new Xtype(".x-panel", InnerEnum.PANEL);

        public static readonly Xtype WINDOW = new Xtype(".x-window", InnerEnum.WINDOW);

        public static readonly Xtype TEXTFIELD = new Xtype(".x-form-text", InnerEnum.TEXTFIELD);

        public static readonly Xtype TEXTAREA = new Xtype(".x-form-textarea", InnerEnum.TEXTAREA);

        public static readonly Xtype COMBOBOX = new Xtype(".x-form-arrow-trigger", InnerEnum.COMBOBOX);


        public static readonly Xtype CHECKBOX = new Xtype("x-form-checkbox", InnerEnum.CHECKBOX);

        //для Ext 4 поиск ".comboopen-trigger"
        //для Ext 4 справочник ".comboedit-trigger"
        public static readonly Xtype DICTIONARY = new Xtype(".x-form-search-trigger", InnerEnum.DICTIONARY);

        public static readonly Xtype RADIO = new Xtype("RADIO", InnerEnum.RADIO);

        public static readonly Xtype LABEL = new Xtype(".x-form-item-label", InnerEnum.LABEL);

        public static readonly Xtype COMBOLISTITEM = new Xtype(".x-combo-list-item", InnerEnum.COMBOLISTITEM);

        private static readonly IList<Xtype> ValueList = new List<Xtype>();

        static Xtype()
        {
            //ValueList.Add(BOX);
            //ValueList.Add(BUTTONGROUP);
            //ValueList.Add(COLORPALETTE);
            //ValueList.Add(COMPONENT);
            //ValueList.Add(CYCLE);
            //ValueList.Add(TREEPANEL);
            //ValueList.Add(VIEWPORT);
            //ValueList.Add(EDITOR);
            //ValueList.Add(EDITORGRID);
            //ValueList.Add(FLASH);
            //ValueList.Add(GRID);
            //ValueList.Add(LISTVIEW);
            ValueList.Add(TEXTAREA);
            ValueList.Add(EASMENUSUBITEM);
            ValueList.Add(MENUSUBITEMCONTAINER);
            ValueList.Add(DATEFIELD);
            ValueList.Add(NUMBERFIELD);
            ValueList.Add(BUTTON);
            ValueList.Add(DATEPICKER);
            ValueList.Add(PANEL);
            ValueList.Add(WINDOW);
            ValueList.Add(TABPANEL);
            ValueList.Add(EASMENU);
            ValueList.Add(TEXTFIELD);
            ValueList.Add(FIRSTROW);
            ValueList.Add(COMBOBOX);
            ValueList.Add(CHECKBOX);
            ValueList.Add(DICTIONARY);
            ValueList.Add(RADIO);
            ValueList.Add(LABEL);
            ValueList.Add(MENUITEM);
            ValueList.Add(COMBOLISTITEM);
        }

        public enum InnerEnum
        {
            //BOX,
            //TREEPANEL,
            //VIEWPORT,
            //BUTTONGROUP,
            //COLORPALETTE,
            //COMPONENT,
            //CYCLE,
            //EDITOR,
            //EDITORGRID,
            //FLASH,
            //GRID,
            //LISTVIEW,
            TEXTAREA,
            FIRSTROW,
            EASMENUSUBITEM,
            MENUSUBITEMCONTAINER,
            NUMBERFIELD,
            DATEFIELD,
            BUTTON,
            DATEPICKER,
            PANEL,
            WINDOW,
            TABPANEL,
            EASMENU,
            TEXTFIELD,
            COMBOBOX,
            CHECKBOX,
            DICTIONARY,
            RADIO,
            LABEL,
            MENUITEM,
            COMBOLISTITEM
        }

        private readonly string _nameValue;
        private readonly InnerEnum _innerEnumValue;

        public String Name
        {
            get
            {
                return ToString().ToLower();
            }
        }

        public static IList<Xtype> Values()
        {
            return ValueList;
        }

        public InnerEnum InnerEnumValue()
        {
            return _innerEnumValue;
        }
        
        public override string ToString()
        {
            return _nameValue;
        }

        public static Xtype ValueOf(string name)
        {
            foreach (var enumInstance in Values())
            {
                if (enumInstance._nameValue == name)
                {
                    return enumInstance;
                }
            }
            throw new ArgumentException(name);
        }
    }

}
